package com.bw.module_mine.ui.mine

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.bw.lib_common.base.BaseViewModel
import com.bw.module_mine.model.MineModel
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

/**
 * @author ytx
 * @date 2025-09-20 08:56
 * @description
 */
@HiltViewModel
class MineViewModel @Inject constructor(private val repository: MineRepository):BaseViewModel() {
    private val mUserInfoLiveData  by lazy{
        MutableLiveData<MineModel>()
    }
    val userInfoLiveData:LiveData<MineModel> = mUserInfoLiveData

    private val mSignLiveData by lazy{
        MutableLiveData<Boolean>()
    }
    val signLiveData:LiveData<Boolean> = mSignLiveData

    private val mSignInLiveDataError by lazy{
        MutableLiveData<String>()
    }
    val signInLiveDataError:LiveData<String> = mSignInLiveDataError

    /**
     * 获得用户信息
     */
    fun getUserInfo(){
        execute(
            action = repository.getUserInfo(),
            onFinish = {
                mUserInfoLiveData.value = it.data
                //存储用户信息

            }
        )
    }

    /**
     * 是否签到
     */
    fun isSign(){
        execute(
            action = repository.isSign(),
            onFinish = {
                mSignLiveData.value = it.data
            },
            onError = {
                mSignLiveData.value = false
            }
        )
    }

    /**
     * 签到
     */
    fun signIn(){
        execute(
            action = repository.signIn(),
            onFinish = {
                if (it.data){
                    mSignLiveData.value = it.data
                }else{
                    mSignInLiveDataError.value = it.msg
                }
            },
            onError = {
                mSignInLiveDataError.value = it
            }
        )
    }



}